package com.cmfi.service.impl;

import java.util.concurrent.CountDownLatch;

import org.eclipse.milo.opcua.sdk.client.OpcUaClient;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.cmfi.dao.AndonDao;
import com.cmfi.domain.userRoleAuthEntity.User;
import com.cmfi.service.inter.AndonService;
import com.cmfi.utils.OpcUaUtil;

@Service
public class AndonServiceImpl implements AndonService {
    @Autowired
    private AndonDao andonDao;
    
    Logger log = LoggerFactory.getLogger(getClass());
    
    public OpcUaClient client = null;
    
    private OpcUaUtil opcUaUtil = new OpcUaUtil();
    
    public static CountDownLatch eventLatch = new CountDownLatch(1);
    
    public boolean save() throws Exception{
    	return andonDao.save() > 0;
    	
    }

	@Override
	public User findCallings() throws Exception {
		User callings = new User();
		callings = andonDao.findCallings();
		return callings;
	}

	@Override
	public void stopplingLines() throws Exception {	
		log.info("[AndonServiceImpl][stopplingLines] is stopping lines.");
		opcUaUtil.writeNode(client, "stopping", 4, 0);//0表示线体急停，点位是Node(4, "stopping")  
	}
}
